package com.ukao.cashregister.ui.stokin;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.RelativeSizeSpan;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.ukao.cashregister.R;
import com.ukao.cashregister.base.MvpActivity;
import com.ukao.cashregister.bean.AddClothingItem;
import com.ukao.cashregister.bean.StockinBean;
import com.ukao.cashregister.bean.StringBean;
import com.ukao.cashregister.consts.SaveParamets;
import com.ukao.cashregister.dialog.SelectNumDialogFragment;
import com.ukao.cashregister.eventbus.AppEvent;
import com.ukao.cashregister.eventbus.PayAmountEvent;
import com.ukao.cashregister.eventbus.UpdateChildChoose;
import com.ukao.cashregister.listener.OnDialogSureClickListener;
import com.ukao.cashregister.pesenter.AddStoragePesenter;
import com.ukao.cashregister.utils.CheckUtils;
import com.ukao.cashregister.utils.DecimalUtil;
import com.ukao.cashregister.utils.L;
import com.ukao.cashregister.utils.T;
import com.ukao.cashregister.view.AddStorageView;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnCheckedChanged;
import butterknife.OnClick;

import static com.ukao.cashregister.R.id.activity_add_clothing_radio_btn_1;
import static com.ukao.cashregister.R.id.serviceAmt;

/**
 * 添加衣物
 */
public class AddClothingActivity extends MvpActivity<AddStoragePesenter> implements AddStorageView{

    @BindView(R.id.activity_add_clothing_close_btn)
    Button mCloseBtn;
    @BindView(R.id.activity_add_clothing_complete_btn)
    Button mCompleteBtn;
    @BindView(activity_add_clothing_radio_btn_1)
    RadioButton mRadioBtn1;
    @BindView(R.id.activity_add_clothing_radio_btn_2)
    RadioButton mRadioBtn2;
    @BindView(R.id.activity_add_clothing_radio_btn_3)
    RadioButton mRadioBtn3;
    @BindView(R.id.activity_add_clothing_radio_btn_4)
    RadioButton mRadioBtn4;
    @BindView(R.id.activity_add_clothing_radio_btn_5)
    RadioButton mRadioBtn5;
    @BindView(R.id.activity_add_clothing_radio_btn_6)
    RadioButton mRadioBtn6;
    @BindView(R.id.activity_add_clothing_radio_btn_7)
    RadioButton mRadioBtn7;
    @BindView(R.id.activity_add_clothing_radio_btn_8)
    RadioButton mRadioBtn8;
    @BindView(R.id.activity_add_clothing_radio_btn_9)
    RadioButton mRadioBtn9;
    @BindView(serviceAmt)
    TextView mRadioBtn10;
    @BindView(R.id.saleAmt )
    TextView saleAmt;
    @BindView(R.id.addsrvAmt)
    TextView addsrvAmt;
    @BindView(R.id.activity_add_clothing_radio_btn_11)
    TextView mRadioBtn11;
    @BindView(R.id.activity_add_clothing_radio_btn_12)
    TextView mRadioBtn12;
    @BindView(R.id.chgSubtotal_layout)
    RelativeLayout chgSubtotalLayout;
    @BindView(R.id.activity_add_clothing_photo_btn)
    Button mPhotoBtn;
    @BindView(R.id.activity_add_clothing_photo_count)
    TextView mPhotoCount;
    @BindView(R.id.activity_add_clothing_radio_group)
    RadioGroup mRadioGroup;
    AddClothingProjectFragment addClothingProjectFragment;
    AddClothingProjectFragment mFragment1, mFragment3, mFragment4, mFragment5, mFragment6,mFragment7,mFragment8,mFragment9;
    ChooseClothingProjectFragment mFragment2;

    private boolean firstUpdate = true;
    private String currentParentId;
    private int currentPosition;
    private String projectId;
    private String businessId;
    private int isCustomNum;
    private String unitText="";
    private String pricingMode="";
    private String orderId="";
    private  String  businessName;
    private String proTypeId="";
    private String proServiceId="";
    private  String  serviceName="";
    private String count="";
    private String brandId="";
    private String brandName="";

    private String flcardDiscount;
    private  String  colorDesc="";
    private  String  flawDesc="";
    private  String  effectDesc="";
    private  String  addServiceDesc="";
    private  String  annexDesc="";
    private String totalMoney="";
    private String totalServiceDescMoney="";
    private   String  businessId9="";
    private   String  businessId4="";
    private String chgSubtotal="";
    private int sortNo;
    private StockinBean.ProListBean mProListBean;
    private List<StringBean> mAnnexDesclist,mColorDesclist,mflawDesclist,meffectDesclist,mServiceDesclist;
    private String clothingName;
    private String afterDiscount;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_clothing);
        ButterKnife.bind(this);
        Intent mIntent = getIntent();
        orderId=mIntent.getStringExtra(ARG_PARAM1);
        pricingMode=mIntent.getStringExtra(ARG_PARAM2);
        sortNo=mIntent.getIntExtra(ARG_PARAM3,0);
        mProListBean=(StockinBean.ProListBean)mIntent.getSerializableExtra(ARG_PARAM4);
        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
        initFrament();
        initView();

    }

    @Override
    protected AddStoragePesenter createPresenter() {
        return new AddStoragePesenter(this);
    }

    private void initFrament(){

        AddClothingProjectFragment firstFragment = findFragment(AddClothingProjectFragment.class);
        if (firstFragment == null) {
            mFragment1=  AddClothingProjectFragment.createBuilder().isSinge(true).enterPos(0).pricingMode(pricingMode).build();
            mFragment2=   ChooseClothingProjectFragment.getInstance(pricingMode,orderId);
            mFragment3 =  AddClothingProjectFragment.createBuilder().isSinge(true).enterPos(2).pricingMode(pricingMode).orderId(orderId).build();
            mFragment4 =  AddClothingProjectFragment.createBuilder().enterPos(3).isEnabledAdd(true).build();
            mFragment5 = AddClothingProjectFragment.createBuilder().enterPos(4) .isSinge(true).isEnabledKeyboard(true).isEnabledSearch(true).isEnabledAdd(true).build();
            mFragment6=  AddClothingProjectFragment.createBuilder().enterPos(5) .isSinge(false).isEnabledKeyboard(true).isEnabledSearch(true).isEnabledAdd(true).build();
            mFragment7= AddClothingProjectFragment.createBuilder().isEnabledKeyboard(true).isEnabledAdd(true).isEnabledSearch(true).enterPos(6).build();
            mFragment8 = AddClothingProjectFragment.createBuilder().isSinge(true).enterPos(7) .isEnabledKeyboard(true).isEnabledAdd(true).isEnabledSearch(true).build();
            mFragment9 = AddClothingProjectFragment.createBuilder().enterPos(8) .isEnabledAdd(true).build();
            loadMultipleRootFragment(R.id.clothing_layout, 0,
                    mFragment1,
                    mFragment2,
                    mFragment3,
                    mFragment4,mFragment5,mFragment6,mFragment7,mFragment8,mFragment9);
            mRadioBtn1.setChecked(true);
        } else {
            mFragment1 = firstFragment;
            mFragment2 = findFragment(ChooseClothingProjectFragment.class);
            mFragment3 = findFragment(AddClothingProjectFragment.class);
            mFragment4 = findFragment(AddClothingProjectFragment.class);
            mFragment5 = findFragment(AddClothingProjectFragment.class);
            mFragment6 = findFragment(AddClothingProjectFragment.class);
            mFragment7 = findFragment(AddClothingProjectFragment.class);
            mFragment8 = findFragment(AddClothingProjectFragment.class);
            mFragment9 = findFragment(AddClothingProjectFragment.class);
        }
    }

    @Override
    protected void initView() {
        if (!CheckUtils.isNull(mProListBean)){
            mRadioBtn1.setText(CheckUtils.isEmptyString(mProListBean.getBusinessName())); /* 项目  */
            clothingName=CheckUtils.isEmptyString(mProListBean.getProductName());
            mRadioBtn2.setText(clothingName); /* 产品名称  */
            String   serveName=mProListBean.getServiceName()+CheckUtils.isEmptyNumber(mProListBean.getCount())+CheckUtils.isEmptyString(mProListBean.getProductUnitText())+"\n";
            String    serveDescribe="";
            if (mProListBean.getCount()>0){
               String  productUnitText =CheckUtils.isEmpty(mProListBean.getProductUnitText())?"":"/"+mProListBean.getProductUnitText();
                serveDescribe="单价："+CheckUtils.isEmptyNumber(mProListBean.getCount())+"元"+productUnitText;
                String   source=serveName+serveDescribe;
                Spannable span = new SpannableString(source);
                span.setSpan(new RelativeSizeSpan(0.8f),serveName.length(),source.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                mRadioBtn3.setText(span);/* 服务  */
            }else{
                mRadioBtn3.setText(serveName);/* 服务  */
            }

            totalMoney=CheckUtils.isEmptyNumber(mProListBean.getSubtotal());
            mRadioBtn11.setText(totalMoney); /* 小计  */

            String name = !CheckUtils.isEmpty(mProListBean.getServiceName()) ? mProListBean.getServiceName() + "  : " : "";
            mRadioBtn10.setText(name+DecimalUtil.multiply(CheckUtils.isEmptyNumber(mProListBean.getServiceAmt()),CheckUtils.isEmptyNumber(mProListBean.getCount()))); /* 服务金额  */
            saleAmt.setText("折后："+ CheckUtils.isEmptyNumber(mProListBean.getSaleAmt())); /* 后金额  */
            addsrvAmt.setText("附加："+ CheckUtils.isEmptyNumber(mProListBean.getAddsrvAmt())); /* 附加金额  */
            if (!CheckUtils.isNull(mProListBean.getPicCnt())&&mProListBean.getPicCnt()!=0){
              //  mPhotoCount.setText(mProListBean.getPicCnt()+"");
             //   mPhotoCount.setVisibility(View.VISIBLE);/*图片数量*/
            }else{
                mPhotoCount.setVisibility(View.GONE);
            }

            Gson mGson=new Gson();
            if (!CheckUtils.isEmpty(mProListBean.getAddServiceDesc())){
                mServiceDesclist = mGson.fromJson(mProListBean.getAddServiceDesc(),
                        new TypeToken<List<StringBean>>() {
                        }.getType());
                String service = "";
                for (StringBean item : mServiceDesclist) {
                    service = service + item.getName() + CheckUtils.isEmptyNumber(item.getAmt())+"元"+"\n";
                }
                if (service.endsWith("\n"))
                    service = service.substring(0, service.length() - 1);
                mRadioBtn9.setText(service); /* 附加  */
            }

            if (!CheckUtils.isEmpty(mProListBean.getAnnexDesc())){
                mAnnexDesclist= mGson.fromJson(mProListBean.getAnnexDesc(),
                        new TypeToken<List<StringBean>>() {
                        }.getType());
                String annex = "";
                for (StringBean item : mAnnexDesclist) {
                    annex = annex + item.getName()+ "\n";

                }
                if (annex.endsWith("\n"))
                    annex = annex.substring(0, annex.length() - 1);
                mRadioBtn4.setText(annex); /* 附件   */
            }
            if (!CheckUtils.isEmpty(mProListBean.getColorDesc())){
                mColorDesclist= mGson.fromJson(mProListBean.getColorDesc(),
                        new TypeToken<List<StringBean>>() {
                        }.getType());
                String color = "";
                for (StringBean item : mColorDesclist) {
                    color = color + item.getName()+"\n";
                }
                if (color.endsWith("\n"))
                    color = color.substring(0, color.length() - 1);
                mRadioBtn5.setText(color); /* 颜色   */
            }
            if (!CheckUtils.isEmpty(mProListBean.getFlawDesc())){
                mflawDesclist= mGson.fromJson(mProListBean.getFlawDesc(),
                        new TypeToken<List<StringBean>>() {
                        }.getType());
                String strflawDesc = "";
                for (StringBean item : mflawDesclist) {
                    strflawDesc = strflawDesc + item.getName()+"\n";
                }
                if (strflawDesc.endsWith("\n"))
                    strflawDesc = strflawDesc.substring(0, strflawDesc.length() - 1);
                mRadioBtn6.setText(strflawDesc); /*瑕疵*/
            }
            if (!CheckUtils.isEmpty(mProListBean.getEffectDesc())){
                meffectDesclist= mGson.fromJson(mProListBean.getEffectDesc(),
                        new TypeToken<List<StringBean>>() {
                        }.getType());
                String streffectDesc = "";
                for (StringBean item : meffectDesclist) {
                    streffectDesc = streffectDesc + item.getName()+"\n";
                }
                if (streffectDesc.endsWith("\n"))
                    streffectDesc = streffectDesc.substring(0, streffectDesc.length() - 1);
                mRadioBtn7.setText(streffectDesc); /*洗后效果*/
            }

            mRadioBtn8.setText(CheckUtils.isEmptyString(mProListBean.getBrandName()));/*品牌*/
            businessId=mProListBean.getBusinessId()+"";  /*项目的businessId*/
            businessName=mProListBean.getBusinessName();/*项目名称*/
            projectId=mProListBean.getMercBusinessId();/*项目id*/
            currentParentId=mProListBean.getProductId()+"";/*衣物详情列表id*/
            proTypeId=mProListBean.getProTypeId()+"";/*衣物详情列表tab*/
            count=CheckUtils.isNull(mProListBean.getCount())? "" :mProListBean.getCount()+"";/*服务数量*/
            serviceName=mProListBean.getServiceName();/*服务名称*/
            proServiceId=mProListBean.getProServiceId()+"";/*服务id*/
            brandId= CheckUtils.isEmptyString(mProListBean.getBrandId());/*品牌id*/
            brandName=  CheckUtils.isEmptyString(mProListBean.getBrandName());/*品牌*/


            if (CheckUtils.isNull(mProListBean.getChgSubtotal())){  /*修改金额*/

                mRadioBtn12.setVisibility(View.GONE);
            }else{
                chgSubtotal=mProListBean.getChgSubtotal()+"";
                mRadioBtn12.setVisibility(View.VISIBLE);
                mRadioBtn12.setText(CheckUtils.isEmptyNumber(mProListBean.getChgSubtotal()));
            }

            if (!CheckUtils.isEmpty(mProListBean.getColorDesc()))colorDesc=mProListBean.getColorDesc();  /*颜色*/
            if(!CheckUtils.isEmpty(mProListBean.getAnnexDesc())) annexDesc=mProListBean.getAnnexDesc();/*附件*/
            if(!CheckUtils.isEmpty(mProListBean.getFlawDesc()))  flawDesc=mProListBean.getFlawDesc();/*瑕疵*/
            if(!CheckUtils.isEmpty(mProListBean.getEffectDesc())) effectDesc= mProListBean.getEffectDesc();/*洗后效果*/
            if(!CheckUtils.isEmpty(mProListBean.getAddServiceDesc())) addServiceDesc= mProListBean.getAddServiceDesc();/*附加服务*/
            isCustomNum=mProListBean.getIsCustomNum();
            unitText=mProListBean.getProductUnitText();
            mFragment1.setDefaultMatchCheck(mProListBean.getMercBusinessId());
            mFragment2.setDefaultMatchCheck(projectId ,proTypeId,currentParentId);
            mFragment3.setProductIdUnit(currentParentId,isCustomNum,unitText,false,proServiceId );
            mFragment4.setDefaultMoreMatchCheck(mAnnexDesclist);
            mFragment5.setDefaultMoreMatchCheck(mColorDesclist);
            mFragment6.setDefaultMoreMatchCheck(mflawDesclist);
            mFragment7.setDefaultMoreMatchCheck(meffectDesclist);
            mFragment8.setDefaultMatchCheck(brandId);
            mFragment9.setDefaultMoreMatchCheck(mServiceDesclist);
        }else{
            updateRadioGroupClickable(false);
        }
    }





    private void updateRadioGroupClickable(boolean clickable) {
        for (int i = 0; i < 9; i++) {
            mRadioGroup.getChildAt(i).setClickable(clickable);
        }
    }





    @Override
    protected boolean useEventBus() {
        return true;
    }

    @OnClick({R.id.activity_add_clothing_close_btn, R.id.activity_add_clothing_complete_btn, R.id.activity_add_clothing_photo_btn,R.id.chgSubtotal_layout})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.activity_add_clothing_close_btn:
                finish();
                break;
            case R.id.activity_add_clothing_complete_btn: //完成
                finishStorage();
                break;
            case R.id.activity_add_clothing_photo_btn: /*跳转相机*/


                break;
            case  R.id.chgSubtotal_layout :
                String subtotal = mRadioBtn11.getText().toString();
                if (!subtotal.isEmpty()&&!CheckUtils.isEmpty(clothingName)){
                    changeSubtotalDialog();
                }
                break;
        }
    }

    /**
     * 修改总计金额
     */
    private void changeSubtotalDialog() {

        SelectNumDialogFragment.createBuilder(getSupportFragmentManager() ).setModificationVisibility(true).setmDialogTitle("修改衣物金额").setUnitTitle("元").
                setUnitPice(clothingName+":￥"+mRadioBtn11.getText().toString()).setListener(mOnDialogSureClickListener).show();

    }

    @SuppressLint("ResourceType")
    @Subscribe
    public void onEvent(AppEvent event) {
        /*更新数据的消息*/
        if (event.getMessage().equals(AppEvent.Message.update))
            if (mRadioGroup.getCheckedRadioButtonId() == R.id.activity_add_clothing_radio_btn_2) {  /*如果是第二按钮*/
                cleanRequestParameter();
                Map map = (Map) event.getData();
                clothingName = map.get("name").toString();
                ((RadioButton) mRadioGroup.findViewById(mRadioGroup.getCheckedRadioButtonId())).setText(clothingName);
                getClothingData(map);
                mFragment3.setProductIdUnit(currentParentId, isCustomNum, unitText, false, "");


            } else {  /*设置选中的内容*/
                AddClothingItem item = (AddClothingItem) event.getData();
                ((RadioButton) mRadioGroup.findViewById(mRadioGroup.getCheckedRadioButtonId())).setText(item.getName());
                switch (mRadioGroup.getCheckedRadioButtonId()) {

                    case R.id.activity_add_clothing_radio_btn_1:  /*项目*/
                        getProjectData(item);
                        cleanRequestParameter();
                        mFragment2.setProjectId(projectId,"");


                        break;
                    case R.id.activity_add_clothing_radio_btn_3:

                        getServiceData(item);
                        String unitpice = item.getUnitpice();
                        if (!CheckUtils.isEmpty(unitpice)) {
                            String selectcount = setSelectService(item);
                            showCalculationAmount(item, selectcount);
                        } else {
                            saleAmt.setVisibility(View.GONE);
                            mRadioBtn10.setVisibility(View.GONE);
                        }


                        break;
                    case R.id.activity_add_clothing_radio_btn_4:

                        annexDesc = item.getSelectDesc();

                        break;
                    case R.id.activity_add_clothing_radio_btn_5:
                        JSONArray mJSONArray = new JSONArray();
                        JSONObject mJSONObject = new JSONObject();
                        try {
                            mJSONObject.put("id", item.getId());
                            mJSONObject.put("name", item.getName());
                            mJSONArray.put(mJSONObject);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        colorDesc =mJSONArray.toString();
                        break;
                    case R.id.activity_add_clothing_radio_btn_6:
                        flawDesc = item.getSelectDesc();
                        break;
                    case R.id.activity_add_clothing_radio_btn_7:
                        effectDesc = item.getSelectDesc();
                        break;
                    case R.id.activity_add_clothing_radio_btn_9:
                        setServiceDescData(item);
                        break;
                    case R.id.activity_add_clothing_radio_btn_8:
                        brandId = item.getId();
                        brandName = item.getName();
                        break;
                }
            }
        else if (event.getMessage().equals(AppEvent.Message.next)) {
            ((RadioButton) findViewById(mRadioGroup.getCheckedRadioButtonId())).setClickable(true);
            ((RadioButton) findViewById(mRadioGroup.getCheckedRadioButtonId() + 1)).setClickable(true);
            mRadioGroup.check(mRadioGroup.getCheckedRadioButtonId() + 1);
        }
    }

    /**
     *设置附加服务内容
     */
    private void setServiceDescData(AddClothingItem item) {
        mRadioBtn9.setText(item.getName());
        addServiceDesc=item.getSelectDesc();
        totalServiceDescMoney=item.getTotalServiceDescMoney();/*附加服务金额*/
        addsrvAmt.setText("附加："+item.getTotalServiceDescMoney());
        mRadioBtn11.setText(DecimalUtil.add(DecimalUtil.multiply(totalMoney,flcardDiscount),totalServiceDescMoney));
    }

    /**
     *设置选中服务内容
     */
    private String setSelectService(AddClothingItem item) {
        String  selectcount=item.getCount();
        count=String.valueOf((DecimalUtil.multiply(selectcount)));
        String   beforeStr=item.getName()+item.getCount()+item.getUnitText();
        String    source=beforeStr+"\n"+item.getUnitpice();
        Spannable span = new SpannableString(source);
        span.setSpan(new RelativeSizeSpan(0.8f),beforeStr.length(),source.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        mRadioBtn3.setText(span);
        return selectcount;
    }

    /**
     *获取选中服务id 与内容
     */
    private void getServiceData(AddClothingItem item) {
        proServiceId="";
        serviceName="";
        count="";
        proServiceId=item.getId();
        serviceName=item.getName();
    }

    /**
     * 添加衣物计算金额
     * @param selectcount  填写的数量
     */
    private void showCalculationAmount(AddClothingItem item, String selectcount) {


        totalMoney=DecimalUtil.multiply(selectcount,item.getPrice());
        mRadioBtn10.setText(businessName+" : "+totalMoney);
        afterDiscount=DecimalUtil.multiply(totalMoney,flcardDiscount);
        mRadioBtn11.setText(DecimalUtil.add(afterDiscount,totalServiceDescMoney));
        saleAmt.setText("折后："+afterDiscount);
        saleAmt.setVisibility(View.VISIBLE);
        mRadioBtn10.setVisibility(View.VISIBLE);

    }

    /**
     * 项目选中的内容信息
     */
    private void getProjectData(AddClothingItem item) {
        projectId="";
        businessId="";
        businessName="";
        projectId= item.getId();
        businessId= item.getBusinessId();
        businessName=item.getName();
    }

    /**
     * 选中的衣物信息
     * @param map
     */
    private void getClothingData(Map map) {
        currentParentId = (String) map.get("parentId");/*衣物详情列表id*/
        currentPosition = (int) map.get("position");
        isCustomNum=(int)map.get("isCustomNum");/*1 显示对话框*/
        unitText=(String)map.get("unitText");/*单位*/
        proTypeId=(String)map.get("proTypeId");
        int saleType=(int)map.get("saleType");
        int discount=(int)map.get("discount");/*价格*/
        flcardDiscount= CheckUtils.isEmptyNumber(discount);


    }

    /**
     * 是否清除衣物
     */
    private void cleanRequestParameter(  ) {
       /*清除衣物*/

            mRadioBtn2.setText("");
            currentParentId="";
            currentPosition=-1;
            isCustomNum=-1;
            unitText="";
            proTypeId="";



        /*清除服务*/
        clearService();
        /*清除附件*/
        annexDesc="";
        mRadioBtn4.setText("");
        /*清除附加*/
        mRadioBtn9.setText("");
        addServiceDesc="";
        /*清除金额*/
        clearMoney();
        /*清除颜色*/
        colorDesc="";
        mRadioBtn5.setText("");
        /*清楚瑕疵*/
        flawDesc="";
        mRadioBtn6.setText("");
        /*清除洗后效果*/
        effectDesc="";
        mRadioBtn7.setText("");
        /*附件服务*/
        addServiceDesc="";
        /*清楚品牌*/
        brandName="";
        brandId="";
        mRadioBtn8.setText("");
        businessId4="";
        businessId9="";
        firstUpdate=true;
        for (int i = 0; i < 9; i++) {
            if (0!=i)
                mRadioGroup.getChildAt(i).setClickable(false);
        }


        PayAmountEvent.postNoData(PayAmountEvent.Message.unselect);
    }

    /**
     * 清除服务选中的信息
     */
    private void clearService() {
        mRadioBtn3.setText("");
        proServiceId="";
        serviceName="";
        count="";
    }


    /**
     * 清除金额
     */
    private void clearMoney() {
        mRadioBtn10.setText("");
        saleAmt.setText("");
        mRadioBtn11.setText("");
        addsrvAmt.setText("");
        chgSubtotal="";
        mRadioBtn12.setText("");
        mRadioBtn12.setVisibility(View.GONE);
    }

    @OnCheckedChanged({activity_add_clothing_radio_btn_1, R.id.activity_add_clothing_radio_btn_2, R.id.activity_add_clothing_radio_btn_3, R.id.activity_add_clothing_radio_btn_4, R.id.activity_add_clothing_radio_btn_5, R.id.activity_add_clothing_radio_btn_6, R.id.activity_add_clothing_radio_btn_7, R.id.activity_add_clothing_radio_btn_8, R.id.activity_add_clothing_radio_btn_9})
    public void onCheckedChanged(CompoundButton view, boolean checked) {
        mRadioGroup.clearCheck();
        //防止重复响应点击
        if (checked) {
            if(firstUpdate&&view.getId()==R.id.activity_add_clothing_radio_btn_4){
                updateRadioGroupClickable(true);
                firstUpdate = false;
            }
            switch (view.getId()) {
                case activity_add_clothing_radio_btn_1:
                    showHideFragment(mFragment1);


                    break;
                case R.id.activity_add_clothing_radio_btn_2:


                    showHideFragment(mFragment2);
                    if(currentParentId!=null&&currentPosition>0){
                        EventBus.getDefault().post(new UpdateChildChoose(currentParentId,currentPosition));
                    }
                    break;
                case R.id.activity_add_clothing_radio_btn_3:


                    showHideFragment(mFragment3);

                    break;
                case R.id.activity_add_clothing_radio_btn_4:
                    if (!CheckUtils.isEmpty(businessId4)&&businessId4.equals(businessId)){
                        mFragment4.setProductId(businessId,true);
                    }else{
                        businessId4=businessId;
                        mFragment4.setProductId(businessId,false);
                    }
                    showHideFragment(mFragment4);

                    break;
                case R.id.activity_add_clothing_radio_btn_5:
                    showHideFragment(mFragment5);

                    break;
                case R.id.activity_add_clothing_radio_btn_6:
                    showHideFragment(mFragment6);

                    break;
                case R.id.activity_add_clothing_radio_btn_7:
                    showHideFragment(mFragment7);
                    break;
                case R.id.activity_add_clothing_radio_btn_8:
                    showHideFragment(mFragment8);

                    break;
                case R.id.activity_add_clothing_radio_btn_9:
                    if (!CheckUtils.isEmpty(businessId9)&&businessId9.equals(businessId)){  /*防止重复加载*/
                        mFragment9.setProductId(businessId,true);
                    }else{
                        businessId9=businessId;
                        mFragment9.setProductId(businessId,false);
                    }
                    showHideFragment(mFragment9);
                    break;

            }
        }

    }

    private OnDialogSureClickListener mOnDialogSureClickListener = new OnDialogSureClickListener() {


        @Override
        public void onSureItemClick(Object message) {
            String flochgSubtotal=(String) message;
            chgSubtotal=DecimalUtil.multiply(flochgSubtotal);
            mRadioBtn12.setText(DecimalUtil.multiply(flochgSubtotal,"1"));
            mRadioBtn12.setVisibility(View.VISIBLE);

        }
    };


    /**
     * 完成入库
     */
    private  void    finishStorage(){
        if(CheckUtils.isEmpty(businessName)){
            T.show("请选择项目");
            return;
        }else if (CheckUtils.isEmpty(currentParentId)){
            T.show("请选择衣物");
            return;
        }else if (CheckUtils.isEmpty(serviceName)){
            T.show("请选择服务");
            return;
        }


        HashMap mHashMap=new HashMap<String,String>();
        mHashMap.put("orderId",orderId);
        mHashMap.put("businessId",businessId);/*项目的businessId*/
        mHashMap.put("mercBusinessId",projectId);/*项目id*/
        mHashMap.put("businessName",businessName);/*项目名称*/
        mHashMap.put("productId",currentParentId);/*衣物详情列表id*/
        mHashMap.put("proTypeId",proTypeId);/*衣物详情列表tab*/
        mHashMap.put("count", count);/*服务数量*/
        mHashMap.put("serviceName", serviceName);/*服务名称*/
        mHashMap.put("proServiceId", proServiceId);/*服务id*/
        mHashMap.put("brandId", brandId);/*品牌id*/
        mHashMap.put("brandName", brandName);/*品牌*/
        mHashMap.put("sortNo", sortNo+"");
        if (!CheckUtils.isEmpty(chgSubtotal)){  mHashMap.put("chgSubtotal", chgSubtotal);/*修改金额*/}
        if (!CheckUtils.isEmpty(colorDesc))mHashMap.put("colorDesc", colorDesc);  /*颜色*/
        if(!CheckUtils.isEmpty(annexDesc))  mHashMap.put("annexDesc", annexDesc);/*附件*/
        if(!CheckUtils.isEmpty(flawDesc))   mHashMap.put("flawDesc", flawDesc);/*瑕疵*/
        if(!CheckUtils.isEmpty(effectDesc))  mHashMap.put("effectDesc", effectDesc);/*洗后效果*/
        if(!CheckUtils.isEmpty(addServiceDesc))   mHashMap.put("addServiceDesc", addServiceDesc);/*附加服务*/
        mHashMap.put("accessToken", SaveParamets.getToken(this));
        L.i("mHashMap="+mHashMap.toString());
        if (!CheckUtils.isNull(mProListBean)) {
            mHashMap.put("id", mProListBean.getId()+"");
            mvpPresenter.stockInUpdate(mHashMap);
        }else{
            mvpPresenter.finishstockIn(mHashMap);
        }
    }
    @Override
    public void loadSuccess(String message) {
        setResult(RESULT_OK);
        finish();
    }

    @Override
    public void loadFail(String message) {
        T.show(message);
    }
}


